package com.yuzhi.common.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;

/**
 * @ClassName: SoilLevelEnum
 * @Author: Mario
 * @Date: 2024-08-16 17:02
 * @Description: 土壤墒情枚举值
 * @ProjectName: drainageapp-area
 * @PackageName: com.yuzhi.common.enums
 */
@Getter
@AllArgsConstructor
public enum SoilMoistureEnum {
    SUITABLE("适墒", 70, 85),
    SLIGHT_DROUGHT("轻度干旱（下等墒）", 50, 60),
    MODERATE_DROUGHT("中度干旱（失墒）", 40, 50),
    SEVERE_DROUGHT("重度干旱（严重失墒）", 30, 40),
    NO("无", 0, 30);

    private final String desc;

    private final double minValue;

    private final double maxValue;

    public static SoilMoistureEnum classifyLevel(double temperatureValue) {
        return Arrays.stream(SoilMoistureEnum.values())
                .filter(level -> level.isInRange(temperatureValue))
                .findFirst()
                .orElseThrow(() -> new IllegalArgumentException("Invalid soil moisture value"));
    }

    private boolean isInRange(double value) {
        return value >= minValue && value < maxValue;
    }
}
